Repository navigation
Add RefasterRuleIndex for single-pass indexed Refaster rule execution. - #6430
Merged
Merged
Conversation
copybara-service
Bot
force-pushed
the
test_1030825963
branch
from
December 4, 2026 00:28
9db659a to
8481f2d
Compare
Applying large suites of `RefasterRule` instances sequentially walks the entire AST once per rule, recomputes `@SuppressWarnings` per rule per declaration, invokes `@Matches` predicates before checking `UFreeIdent` parameter types, and repeats reflective lookups in `Template.infer`. On suites with thousands of rules, AST traversal, suppression checks, and failed `Unifier` allocations dominate runtime. Introduce `RefasterRuleIndex` to execute a collection of `RefasterRule` instances in a single AST pass while preserving `RefasterScanner` semantics, including traversal order, parenthesis skipping, synthetic class-member block matching, comment rejection, and lexical `@SuppressWarnings` / self-suppression. The index runs a conservative per-compilation-unit AST symbol and type-closure pre-filter extracted via fail-safe package-private `UTree.collectRequirements` hooks, dispatches `ExpressionTemplate` rules via fail-safe `UExpression.classifyRootDispatch` by `(Tree.Kind, methodName)` and `BlockTemplate` rules by first-statement `(Tree.Kind, methodName)` plus a required statement-kind `EnumSet` with wildcard fallbacks, and shares a per-compilation-unit `MatchContext` and `VisitorState` across `Unifier` instances. In addition, `UMatches` rejects incompatible `UClassType` parameters before invoking `Matcher` predicates, `BlockTemplate` guards first-statement kind before allocating a `Unifier`, and `Template` caches javac reflection handles. All index structures live outside serialized `RefasterRule` graphs so no new fields are serialized; adding package-private methods on `Template` and `UTree` classes changes their default `serialVersionUID`, so serialized `.refaster` artifacts must be compiled against the matching runtime. PiperOrigin-RevId: 1035840958
copybara-service
Bot
force-pushed
the
test_1030825963
branch
from
December 4, 2026 01:07
8481f2d to
3bb7801
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add RefasterRuleIndex for single-pass indexed Refaster rule execution.
Applying large suites of
RefasterRuleinstances sequentially walks the entire AST once per rule, recomputes@SuppressWarningsper rule per declaration, invokes@Matchespredicates before checkingUFreeIdentparameter types, and repeats reflective lookups inTemplate.infer. On suites with thousands of rules, AST traversal, suppression checks, and failedUnifierallocations dominate runtime.Introduce
RefasterRuleIndexto execute a collection ofRefasterRuleinstances in a single AST pass while preservingRefasterScannersemantics, including traversal order, parenthesis skipping, synthetic class-member block matching, comment rejection, and lexical@SuppressWarnings/ self-suppression. The index runs a conservative per-compilation-unit AST symbol and type-closure pre-filter extracted via fail-safe package-privateUTree.collectRequirementshooks, dispatchesExpressionTemplaterules via fail-safeUExpression.classifyRootDispatchby(Tree.Kind, methodName)andBlockTemplaterules by first-statement(Tree.Kind, methodName)plus a required statement-kindEnumSetwith wildcard fallbacks, and shares a per-compilation-unitMatchContextandVisitorStateacrossUnifierinstances. In addition,UMatchesrejects incompatibleUClassTypeparameters before invokingMatcherpredicates,BlockTemplateguards first-statement kind before allocating aUnifier, andTemplatecaches javac reflection handles. All index structures live outside serializedRefasterRulegraphs so no new fields are serialized; adding package-private methods onTemplateandUTreeclasses changes their defaultserialVersionUID, so serialized.refasterartifacts must be compiled against the matching runtime.